/********************************************************************************
* @file    main.c
* @author  jianqiang.xue
* @version V1.0.0
* @date    2021-04-03
* @brief   无
********************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>

#include "cx32l003_hal.h"

#include "os_api.h"

#include "bsp_system_clock.h"
#include "bsp_i2c.h"
#include "bsp_uart.h"
#include "log.h"
/* Private Includes ----------------------------------------------------------*/
#include "ls_syscfg.h"
#include "ls_gpio.h"
/* External Variables --------------------------------------------------------*/
extern uint8_t app_main_init(void);

/* Private Function Prototypes -----------------------------------------------*/

/**
 * @brief  Initialize the peripherals and hardware
 */
void hardware_init(void) {
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();
    /* Configure the system clock to HIRC 24MHz*/
    bsp_system_clock_config();
}

/**
 * @brief  initialize and start the system
 */
int main(void) {
    // 硬件外设初始化(不允许包含os部分代码,因为os未启动会导致程序异常死机)
    hardware_init();
    // os系统初始化
    os_kernel_initialize();
#if LS_LOG_SWITCH
    log_init();
#endif
    ls_gpio_init();
    // app功能初始化
    app_main_init();
    // 系统启动
    os_kernel_start();
}
